package itsm.isperp.framework.web.servlet.http;

import java.io.IOException;
import java.util.zip.GZIPOutputStream;

import javax.servlet.ServletOutputStream;
import javax.servlet.WriteListener;

/**
 * 
 * 
 * 
 * @author lizx
 * @date 2014-8-2
 * @since 1.0
 * 
 */
class GZipServletOutputStream extends ServletOutputStream {
	private GZIPOutputStream gzipOutputStream = null;
	private ServletOutputStream servletOutputStream = null;

	public GZipServletOutputStream(ServletOutputStream output)
			throws IOException {
		super();
		this.servletOutputStream = output;
		this.gzipOutputStream = new GZIPOutputStream(this.servletOutputStream);
	}

	@Override
	public void close() throws IOException {
		this.gzipOutputStream.close();
	}

	@Override
	public void flush() throws IOException {
		this.gzipOutputStream.flush();
	}

	@Override
	public void write(byte b[]) throws IOException {
		this.gzipOutputStream.write(b);
	}

	@Override
	public void write(byte b[], int off, int len) throws IOException {
		this.gzipOutputStream.write(b, off, len);
	}

	@Override
	public void write(int b) throws IOException {
		this.gzipOutputStream.write(b);
	}

	@Override
	public boolean isReady() {

		return servletOutputStream.isReady();
	}

	@Override
	public void setWriteListener(WriteListener writeListener) {
		servletOutputStream.setWriteListener(writeListener);
	}
}
